import request from '@/config/axios'

// 告警记录 VO
export interface AlarmRecordVO {
  alarmLevel: number // 告警级别
  alarmTime: Date // 告警时间
  alarmContent: string // 告警内容
  signalIds: string // 信号ID
  monitorDeviceId: number // 被监测设备ID
  monitorDeviceOutId: string // 被监测设备外部ID
  monitorDeviceName: string // 被监测设备名称
  terminalDeviceIds: string // 终端设备ID
  terminalDeviceOutIds: string // 终端设备外部ID
  terminalDeviceNames: string // 终端设备名称
  taskId: number // 任务ID
  taskName: string // 任务名称
  ruleId: number // 规则ID
  ruleName: string // 规则名称
  alarmTriggerId: number // 触发器ID
  alarmTriggerName: string // 触发器名称
  state: number // 状态(0:待处理 1:确认 2:需修改 3:待确认)
  stateChangeTime: Date // 状态变更时间
  remark: string // 处理意见
}

// 告警记录 API
export const AlarmRecordApi = {
  // 查询告警记录分页
  getAlarmRecordPage: async (params: any) => {
    return await request.get({ url: `/vmiot/alarm-record/page`, params })
  },

  // 获得告警记录列表(租户)
  getAlarmRecordList4Tenant: async (tenantId: number) => {
    return await request.get({
      url: `/vmiot/alarm-record/getAlarmRecordList4Tenant?tenantId=` + tenantId
    })
  },

  // 查询告警记录详情
  getAlarmRecord: async (id: number) => {
    return await request.get({ url: `/vmiot/alarm-record/get?id=` + id })
  },

  // 查询分组统计数量
  getGroupCount: async (params: any) => {
    return await request.get({
      url: `/vmiot/alarm-record/getGroupCount?tenantId=${params.tenantId}&timeRangeType=${params.timeRangeType}&groupField=${params.groupField}`
    })
  },

  // 查询我的分组统计数量
  getMyGroupCount: async (params: any) => {
    return await request.get({
      url: `/vmiot/alarm-record/getMyGroupCount?timeRangeType=${params.timeRangeType}&groupField=${params.groupField}`
    })
  },

  // 新增告警记录
  createAlarmRecord: async (data: AlarmRecordVO) => {
    return await request.post({ url: `/vmiot/alarm-record/create`, data })
  },

  // 修改告警记录
  updateAlarmRecord: async (data: AlarmRecordVO) => {
    return await request.put({ url: `/vmiot/alarm-record/update`, data })
  },

  // 修改告警记录状态
  updateAlarmRecordState: async (data: AlarmRecordVO) => {
    return await request.put({ url: `/vmiot/alarm-record/updateState`, data })
  },

  // 删除告警记录
  deleteAlarmRecord: async (id: number) => {
    return await request.delete({ url: `/vmiot/alarm-record/delete?id=` + id })
  },

  // 导出告警记录 Excel
  exportAlarmRecord: async (params) => {
    return await request.download({ url: `/vmiot/alarm-record/export-excel`, params })
  }
}
